/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ejercicios5_12;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

/**
 *
 * @author Mañana
 */
public class Ejercicios5_12 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        try {
            //Declaramos el Archivo
            //Buscamos el Fichero que queremos mostrar
            File newTextFile = new File("./QUIJOTE.txt");
            FileReader fr = new FileReader(newTextFile);
            int i = 0;
            int cont = 0;
            int penta = 0;
            String pal = " ";
            boolean leopal = false;
            while ((i = fr.read()) != -1) {
                if (Character.isLetter((char) i)) {
                    if (leopal) {
                        pal += (char) i;
                    } else {
                        leopal = true;
                        pal += (char) i;
                    }

                } else {
                    if (leopal) {
                        leopal = false;
                        cont++;
                        if(esPentavocálica(pal)==true){
                            penta++;
                        }
                        pal = "";
                    } else {
                    }
                }
            }
            fr.close();

            System.out.println("Palabras: " + cont);
            System.out.println("Palabras Pentavólicas: " + penta);

        } catch (IOException ex) {
            System.out.println("Excepcion de IO.");
        }
    }

    public static int esVocal(char i) {
        char c = Character.toLowerCase(i);
        int vocal = -1;

        switch (c) {
            case 'a':
            case 'á':
                return 0;

            case 'e':
            case 'é':
                return 1;

            case 'i':
            case 'í':
                return 2;

            case 'o':
            case 'ó':
                return 3;

            case 'u':
            case 'ü':
            case 'ú':
                return 4;

        }
        return vocal;
    }

    public static boolean esPentavocálica(String pal) {
        boolean pentavocalica = false;
        int conta = -1, conte = -1, conti = -1, conto = -1, contu = -1;
        for (int i = 0; i < pal.length(); i++) {
            switch (esVocal(pal.charAt(i))) {
                case 0:
                    conta++;
                    break;
                case 1:
                    conte++;
                    break;
                case 2:
                    conti++;
                    break;
                case 3:
                    conto++;
                    break;
                case 4:
                    contu++;
                    break;
            }
        }
        return (conta !=-1&&conte !=-1&&conti !=-1&&conto !=-1&&contu !=-1);
    }
}
